#include "IntTimer.h"
#include "System\F2806x_Device.h"

// 80Mhz SYSCLKOUT (80Mhz/1)
#define TICKSPERSEC 80000000L

void IntTimer::Init(float freqMHZ, float periodUS)
{
	// Initialize timer period:
	m_CPUFreqInMHz = freqMHZ;
	m_PeriodInUSec = periodUS;
	Uint32 temp = (Uint32) (freqMHZ * periodUS) - 1; // Counter decrements once every TPR+1 System Clock Cycles
	CpuTimer1Regs.PRD.all = temp; // set period

    CpuTimer1Regs.TPR.all  = 0; // Set pre-scale counter to divide by 1 (SYSCLKOUT):
    CpuTimer1Regs.TPRH.all  = 0;

    // Initialize timer control register:
    CpuTimer1Regs.TCR.bit.TSS = 1;      // 1 = Stop timer, 0 = Start/Restart Timer
    CpuTimer1Regs.TCR.bit.TRB = 1;      // 1 = reload timer
    CpuTimer1Regs.TCR.bit.SOFT = 0;
    CpuTimer1Regs.TCR.bit.FREE = 0;     // Timer Free Run Disabled
    CpuTimer1Regs.TCR.bit.TIE = 1;      // 0 = Disable/ 1 = Enable Timer Interrupt

    CpuTimer1Regs.TCR.bit.TSS = 0;      // start timer

	// Reset interrupt counter:
    m_InterruptCount = 0;

}

